package com.atguigu4.search_sort.exer1;

/**
 * ClassName: ArrayExoer_01
 * Package: com.atguigu4.search_sort.exer1
 * Description:
 *

 案例：数组的缩容：

 现有数组 int[] arr={1,2,3,4,5,6,7}。现需删除数组中索引为4的元素。
 * @Author xiao_qi
 * @Create 2024/3/15 13:26
 * @Version 1.0
 */
public class ArrayExoer_01 {
    public static void main(String[] args) {

        int[] arr = new int[]{1,2,3,4,5,6,7};
        int index =4;
        int [] arr1 = new int[arr.length -1];
        for (int i = 0; i < index; i++) {
            arr1[i] = arr[i];
        }
        for (int i = index; i < arr.length -1; i++) {

            arr1[i] = arr[i +1];//加一才能消除下标为4的元素
        }
        arr = arr1;
        for (int i = 0; i < arr.length ; i++) {
            System.out.print(arr[i] + "\t");
        }
    }
}
